<?php
namespace Home\Controller;

use Common\Controller\UserBaseController;

/**
 * 首页控制器
 */
class PeriodController extends UserBaseController
{

    /**
     *
     */
    public function index()
    {
        $c_type = $_GET['lottery'];
        $c_time = $_GET['_'];
        $kaip   = S('setting');
        $kaipan = unserialize($kaip['is_kaipan']);

        $new_time = substr($c_time, 0, strlen($c_time) - 3);
        $day      = date("Y-m-d");
        $data     = array();
        switch ($c_type) {
            //六合彩
            case 'HK6': //六合彩 彩种id 12
                header('Content-type:text/json');

                if ($kaipan[12] == 1) {
                    $open_time = S('op_time_12');

                    if (empty($open_time)) {
                        $condition['c_id'] = 12;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_12', $open_time);
                    }

                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = $v['kp_time'];
                        $fp_time[$k] = $v['fp_time'];
                        $kj_time[$k] = $v['kj_time'];
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                            // $data['drawNumber']=$v['periods']; // 本期期期号
                            //$data['pnumber']=$v['periods']-1; // 上期期号

                            $yesday             = date('Y-m-d', time()) . ' 00:00:00';
                            $yesday             = strtotime($yesday);
                            $today              = date('Y-m-d', time()) . ' 04:17:03';
                            $today              = strtotime($today);
                            $now                = time();
                            $day1               = date('Y');
                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);

                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            //幸运飞艇
            case 'XYFT': //幸运飞艇 彩种id 5
                header('Content-type:text/json');

                if ($kaipan[5] == 1) {
                    $open_time = S('op_time_5');

                    if (empty($open_time)) {
                        $condition['c_id'] = 5;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_5', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                            // $data['drawNumber']=$v['periods']; // 本期期期号
                            //$data['pnumber']=$v['periods']-1; // 上期期号

                            $yesday = date('Y-m-d', time()) . ' 00:00:00';
                            $yesday = strtotime($yesday);
                            $today  = date('Y-m-d', time()) . ' 04:17:03';
                            $today  = strtotime($today);
                            $now    = time();
                            if ($now >= $yesday && $now < $today) {
                                $day1 = date("Ymd", strtotime("-1 day"));
                            } else {
                                $day1 = date('Ymd');
                            }
                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            /*if($v['periods']>=132||$v['kj_time']=='00:02:03'){        //开奖日期跨过12点判断
                            $day2=date("Ymd",strtotime("-1 day"));
                            $data['drawNumber']=$day2. str_pad($v['periods'],3, "0", STR_PAD_LEFT);
                            }else{

                            $data['drawNumber']=$day1. str_pad($v['periods'],3, "0", STR_PAD_LEFT);
                            }

                            if($v['periods']>=132||$v['kj_time']=='00:02:03'){
                            $day2=date("Ymd",strtotime("-1 day"));
                            $data['pnumber']=$day2. str_pad($v['periods']-1,3, "0", STR_PAD_LEFT);
                            }else{

                            $data['pnumber']=$day1. str_pad($v['periods']-1,3, "0", STR_PAD_LEFT);
                            }*/

                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'BJPK10': //北京PK10 彩种id 4
                header('Content-type:text/json');
                $open_time = S('op_time_4');
                if ($kaipan[4] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 4;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_4', $open_time);
                    }

                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $value = S('setting');

                            $n_day = strtotime(date('Ymd'));
                            $jiane = ($n_day - $value['bjpk_day']) / (24 * 60 * 60);
                            if ($jiane == 1) {
                                $data['drawNumber'] = $value['bjpk_period'] + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['bjpk_period'] + $v['periods'] - 1; // 上期期号
                            } else {
                                $data['drawNumber'] = $value['bjpk_period'] + ($jiane - 1) * 179 + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['bjpk_period'] + ($jiane - 1) * 179 + $v['periods'] - 1; // 上期期号
                            }
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'CQSSC': //重庆时时彩 彩种id 1
                header('Content-type:text/json');
                $open_time = S('op_time_1');
                if ($kaipan[1] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 1;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_1', $open_time);
                    }
                    $day1 = date('Ymd');

                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {
                            //  print_r($kp_time[$k]);exit;
                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            /* if($v['periods']<10){
                            $data['drawNumber']=$day1.'0'.$v['periods']; // 本期期期号
                            }else{
                            $data['drawNumber']=$day1.$v['periods']; // 本期期期号
                            }*/
                            $data['pnumber'] = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            /*if($v['periods']<11){
                            $data['pnumber']=$day1.'0'.$v['periods']-1; // 上期期号

                            }else{
                            $data['pnumber']=$day1.$v['periods']-1; // 上期期号
                            }*/
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($fp_time);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'XJSSC': //新疆时时彩 彩种id 2
                header('Content-type:text/json');
                $open_time = S('op_time_2');
                if ($kaipan[2] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 2;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_2', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                            /* if($v['periods']<10){
                            $data['drawNumber']=$day1.'0'.$v['periods']; // 本期期期号
                            }else{
                            $data['drawNumber']=$day1.$v['periods']; // 本期期期号
                            }
                            if($v['periods']<11){
                            $data['pnumber']=$day1.'0'.$v['periods']-1; // 上期期号
                            }else{
                            $data['pnumber']=$day1.$v['periods']-1; // 上期期号
                            }*/
                            if ($v['periods'] < 85) {
                                //开奖日期跨过12点判断
                                $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            } else {
                                $day2               = date("Ymd", strtotime("-1 day"));
                                $data['drawNumber'] = $day2 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            }
                            if ($v['periods'] <= 85) {
                                $data['pnumber'] = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            } else {
                                $day2            = date("Ymd", strtotime("-1 day"));
                                $data['pnumber'] = $day2 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            }

                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'TJSSC': //天津时时彩 彩种id 3
                header('Content-type:text/json');
                $open_time = S('op_time_3');
                if ($kaipan[3] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 3;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_3', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                            /*if($v['periods']<10){
                            $data['drawNumber']=$day1.'0'.$v['periods']; // 本期期期号
                            }else{
                            $data['drawNumber']=$day1.$v['periods']; // 本期期期号
                            }
                            if($v['periods']<11){
                            $data['pnumber']=$day1.'0'.$v['periods']-1; // 上期期号
                            }else{
                            $data['pnumber']=$day1.$v['periods']-1; // 上期期号
                            }*/
                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'XYNC': //重庆幸运农场 彩种id 8
                header('Content-type:text/json');
                $open_time = S('op_time_8');
                if ($kaipan[8] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 8;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_8', $open_time);
                    }

                    $yesday = date('Y-m-d', time()) . ' 23:53:03';
                    $yesday = strtotime($yesday);
                    $today  = date('Y-m-d', time()) . ' 23:59:59';
                    $today  = strtotime($today);
                    $now    = time();
                    if ($now >= $yesday && $now < $today) {
                        $day1 = date("Ymd", strtotime("+1 day"));
                    } else {
                        $day1 = date('Ymd');
                    }
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);

                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;

            case 'GDKLSF': //广东快乐十分 彩种id 6
                header('Content-type:text/json');
                $open_time = S('op_time_6');
                if ($kaipan[6] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 6;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_6', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                            /*if($v['periods']<10){
                            $data['drawNumber']=$day1.'0'.$v['periods']; // 本期期期号
                            }else{
                            $data['drawNumber']=$day1.$v['periods']; // 本期期期号
                            }
                            if($v['periods']<11){
                            $data['pnumber']=$day1.'0'.$v['periods']-1; // 上期期号
                            }else{
                            $data['pnumber']=$day1.$v['periods']-1; // 上期期号
                            }*/
                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'GXK3': //广西快三 彩种id 7
                header('Content-type:text/json');
                $open_time = S('op_time_7');
                if ($kaipan[7] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 7;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_7', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                            /*if($v['periods']<10){
                            $data['drawNumber']=$day1.'0'.$v['periods']; // 本期期期号
                            }else{
                            $data['drawNumber']=$day1.$v['periods']; // 本期期期号
                            }
                            if($v['periods']<11){
                            $data['pnumber']=$day1.'0'.$v['periods']-1; // 上期期号
                            }else{
                            $data['pnumber']=$day1.$v['periods']-1; // 上期期号
                            }*/
                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'HUBK3': //湖北快三 彩种id 18
                header('Content-type:text/json');
                $open_time = S('op_time_18');
                if ($kaipan[18] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 18;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_18', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                            /*if($v['periods']<10){
                            $data['drawNumber']=$day1.'0'.$v['periods']; // 本期期期号
                            }else{
                            $data['drawNumber']=$day1.$v['periods']; // 本期期期号
                            }
                            if($v['periods']<11){
                            $data['pnumber']=$day1.'0'.$v['periods']-1; // 上期期号
                            }else{
                            $data['pnumber']=$day1.$v['periods']-1; // 上期期号
                            }*/
                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'HEBK3': //河北快三 彩种id 19
                header('Content-type:text/json');
                $open_time = S('op_time_19');
                if ($kaipan[19] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 19;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_19', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间
                            /*if($v['periods']<10){
                            $data['drawNumber']=$day1.'0'.$v['periods']; // 本期期期号
                            }else{
                            $data['drawNumber']=$day1.$v['periods']; // 本期期期号
                            }
                            if($v['periods']<11){
                            $data['pnumber']=$day1.'0'.$v['periods']-1; // 上期期号
                            }else{
                            $data['pnumber']=$day1.$v['periods']-1; // 上期期号
                            }*/
                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'JSK3': //江苏快三 彩种id 20
                header('Content-type:text/json');
                $open_time = S('op_time_20');
                if ($kaipan[20] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 20;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_20', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 3, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'PCEGG': //PC蛋蛋 彩种id 11
                header('Content-type:text/json');
                $open_time = S('op_time_11');
                if ($kaipan[11] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 11;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_11', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $value = S('setting');
                            $n_day = strtotime(date('Ymd'));
                            $jiane = ($n_day - $value['bjk8_day']) / (24 * 60 * 60);
                            if ($jiane == 1) {
                                $data['drawNumber'] = $value['bjk8_period'] + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['bjk8_period'] + $v['periods'] - 1; // 上期期号
                            } else {
                                $data['drawNumber'] = $value['bjk8_period'] + ($jiane - 1) * 179 + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['bjk8_period'] + ($jiane - 1) * 179 + $v['periods'] - 1; // 上期期号
                            }

                            // $data['drawNumber']=$day1. str_pad($v['periods'],3, "0", STR_PAD_LEFT);
                            // $data['pnumber']=$day1. str_pad($v['periods']-1,3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'BJKL8': //北京快8 彩种id 9
                header('Content-type:text/json');
                $open_time = S('op_time_9');
                if ($kaipan[9] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 9;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_9', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $value = S('setting');
                            $n_day = strtotime(date('Ymd'));
                            $jiane = ($n_day - $value['bjk8_day']) / (24 * 60 * 60);
                            if ($jiane == 1) {
                                $data['drawNumber'] = $value['bjk8_period'] + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['bjk8_period'] + $v['periods'] - 1; // 上期期号
                            } else {
                                $data['drawNumber'] = $value['bjk8_period'] + ($jiane - 1) * 179 + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['bjk8_period'] + ($jiane - 1) * 179 + $v['periods'] - 1; // 上期期号
                            }

                            // $data['drawNumber']=$day1. str_pad($v['periods'],3, "0", STR_PAD_LEFT);
                            //  $data['pnumber']=$day1. str_pad($v['periods']-1,3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'TWBG': //台湾宾果 彩种id 22
                header('Content-type:text/json');
                $open_time = S('op_time_22');
                if ($kaipan[22] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 22;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_22', $open_time);
                    }
                    $day1 = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $value = S('setting');
                            $n_day = strtotime(date('Ymd'));
                            $jiane = ($n_day - $value['twbg_day']) / (24 * 60 * 60);
                            if ($jiane == 1) {
                                $data['drawNumber'] = $value['twbg_period'] + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['twbg_period'] + $v['periods'] - 1; // 上期期号
                            } else {
                                $data['drawNumber'] = $value['twbg_period'] + ($jiane - 1) * 203 + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['twbg_period'] + ($jiane - 1) * 203 + $v['periods'] - 1; // 上期期号
                            }

                            // $data['drawNumber']=$day1. str_pad($v['periods'],3, "0", STR_PAD_LEFT);
                            //  $data['pnumber']=$day1. str_pad($v['periods']-1,3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;

            case 'JND': //加拿大3.5 彩种id 15
            case 'JNDKL8':
                header('Content-type:text/json');

                //从接口获取最新一期数据
                // $url='http://a.apiplus.net/newly.do?token=b3a57cb626f015a6&code=cakeno&rows=1&format=json'; //接口地址
                //时间校验
                $time_change = 0;

                //$new_result=get_http($url);
                $new_result = S('JND_result');
                $result     = json_decode($new_result, true);
                $periods    = $result['data'][0]['expect'] + 1;
                $kj_time    = $result['data'][0]['opentimestamp'] + $time_change;
                $kj_time    = $kj_time + 210;
                $fp_time    = $kj_time - 10;
                $kp_time    = $kj_time - 210;
                //夏令时
                // $time=1;
                // if($time==1){
                //     $jiu=date('H:i',$kj_time);
                //     if($jiu=='19:03'){
                //             $kj_time=$kj_time-180+7440;
                // $fp_time=$fp_time-180+7440;
                // $kp_time=$kp_time-180+7440;
                //     }
                // }else{

                // }
                $kj_time2           = date('H:i:s', $kj_time);
                $fp_time2           = date('H:i:s', $fp_time);
                $kp_time2           = date('H:i:s', $kp_time);
                $data[1]['periods'] = $periods;
                $data[1]['kp_time'] = $kp_time2;
                $data[1]['fp_time'] = $fp_time2;
                $data[1]['kj_time'] = $kj_time2;

                $ndata                = serialize($data);
                $update_array['data'] = $ndata;
                $result               = M('open_time')->where('c_id=15')->save($update_array);
                //////////////////////////////////////////////////////////////////

                $data = array();
                // $open_time=S('op_time_15');
                if ($kaipan[15] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 15;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_15', $open_time);
                    }
                    $day = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time = strtotime($day . ' ' . $v['kj_time']);
                        $n_time  = time();
                        if ($n_time > $kp_time && $n_time < $kj_time) {

                            $data['openTime']  = $kp_time . '000'; //开盘时间
                            $data['closeTime'] = $fp_time . '000'; //封盘时间
                            $data['drawTime']  = $kj_time . '000'; //开奖时间

                            $data['drawNumber'] = $v['periods']; // 本期期期号
                            // $data['pnumber']=$value['jnd_period']+($jiane-1)*179+$v['periods']-1; // 上期期号

                            if ($n_time > $kp_time && $n_time < $fp_time) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }

                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'GXKLSF': //广西快乐十分 彩种id 10
                header('Content-type:text/json');
                $open_time = S('op_time_10');
                if ($kaipan[10] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 10;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_10', $open_time);
                    }
                    $day1 = date('Ymd');
                    if ($new_year == date('Ymd')) {
                        //判断是否是新年
                        $data['gxklsf']     = date('Y') . '00101';
                        $data['gxklsf_day'] = date('Y') . '0101';
                        $model_setting      = D('Base');
                        $result             = $model_setting->updateSetting($data);
                        S('setting', null);
                    }

                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {

                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $kl_num = (int) substr($kaip['gxklsf'], -5, 3);

                            $n_day = strtotime(date('Ymd'));
                            $jiane = floor(($n_day - $kaip['gxklsf_day']) / (24 * 60 * 60));

                            $nkl_num  = $kl_num + $jiane;
                            $new_year = date('Y') . '0101';

                            if ($jiane == 0) {
                                $data['drawNumber'] = date('Y') . str_pad($kl_num, 3, "0", STR_PAD_LEFT) . str_pad($v['periods'], 2, "0", STR_PAD_LEFT); // 本期期期号
                                if ($v['periods'] == 1) {
                                    $data['pnumber'] = date('Y') . str_pad($kl_num, 3, "0", STR_PAD_LEFT) . str_pad($v['periods'], 2, "0", STR_PAD_LEFT); // 上期期号
                                } else {
                                    $data['pnumber'] = date('Y') . str_pad($kl_num, 3, "0", STR_PAD_LEFT) . str_pad($v['periods'] - 1, 2, "0", STR_PAD_LEFT); // 上期期号
                                }
                            } else {
                                $data['drawNumber'] = date('Y') . str_pad($nkl_num, 3, "0", STR_PAD_LEFT) . str_pad($v['periods'], 2, "0", STR_PAD_LEFT); // 本期期期号
                                if ($v['periods'] == 1) {
                                    $data['pnumber'] = date('Y') . str_pad($nkl_num, 3, "0", STR_PAD_LEFT) . str_pad($v['periods'], 2, "0", STR_PAD_LEFT); // 上期期号
                                } else {
                                    $data['pnumber'] = date('Y') . str_pad($nkl_num, 3, "0", STR_PAD_LEFT) . str_pad($v['periods'] - 1, 2, "0", STR_PAD_LEFT); // 上期期号
                                }
                            }

                            // $data['drawNumber']=$day1. str_pad($v['periods'],3, "0", STR_PAD_LEFT);   //左侧填充0
                            // $data['pnumber']=$day1. str_pad($v['periods']-1,3, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;

            case 'FFC': //分分彩 彩种id 13
                header('Content-type:text/json');

                $open_time = S('op_time_13');

                if ($kaipan[13] == 1) {

                    if (empty($open_time)) {
                        $open_time = include APP_PATH . 'Common/Common/ffctime.php';

                        S('op_time_13', $open_time);
                    }
                    $day1 = date('Ymd');

                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {
                            //  print_r($kp_time[$k]);exit;
                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 4, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 4, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($fp_time);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'QQFFC': //分分彩 彩种id 16
                header('Content-type:text/json');

                $open_time = S('op_time_13');

                if ($kaipan[16] == 1) {

                    if (empty($open_time)) {
                        $open_time = include APP_PATH . 'Common/Common/ffctime.php';

                        S('op_time_13', $open_time);
                    }
                    $day1 = date('Ymd');

                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {
                            //  print_r($kp_time[$k]);exit;
                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 4, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 4, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($fp_time);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;

            case 'TXFFC': //腾讯分分彩 彩种id 17
                header('Content-type:text/json');

                $open_time = S('op_time_17');

                if ($kaipan[17] == 1) {

                    if (empty($open_time)) {
                        $open_time = include APP_PATH . 'Common/Common/ffctime.php';

                        S('op_time_17', $open_time);
                    }
                    $day1 = date('Ymd');

                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {
                            //  print_r($kp_time[$k]);exit;
                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $data['drawNumber'] = $day1 . str_pad($v['periods'], 4, "0", STR_PAD_LEFT);
                            $data['pnumber']    = $day1 . str_pad($v['periods'] - 1, 4, "0", STR_PAD_LEFT);
                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($fp_time);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;
            case 'SHSSL': //腾讯分分彩 彩种id 21
                header('Content-type:text/json');

                $open_time = S('op_time_21');
                if ($kaipan[21] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 21;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);

                        S('op_time_21', $open_time);
                    }
                    $day = date('Ymd');
                    foreach ($open_time as $k => $v) {
                        $kp_time = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time = strtotime($day . ' ' . $v['kj_time']);
                        $n_time  = time();
                        if ($n_time > $kp_time && $n_time < $kj_time) {

                            $data['openTime']  = $kp_time . '000'; //开盘时间
                            $data['closeTime'] = $fp_time . '000'; //封盘时间
                            $data['drawTime']  = $kj_time . '000'; //开奖时间

                            $data['drawNumber'] = $v['periods']; // 本期期期号
                            // $data['pnumber']=$value['jnd_period']+($jiane-1)*179+$v['periods']-1; // 上期期号

                            if ($n_time > $kp_time && $n_time < $fp_time) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }

                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($data);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;

            case 'TWWF': //台湾五分 彩种id 23
                header('Content-type:text/json');
                $open_time = S('op_time_23');
                if ($kaipan[23] == 1) {
                    if (empty($open_time)) {
                        $condition['c_id'] = 23;
                        $op_time           = M('open_time')->where($condition)->getField('data');
                        $open_time         = unserialize($op_time);
                        // print_r($open_time);exit;
                        S('op_time_23', $open_time);
                    }
                    $day1 = date('Ymd');

                    foreach ($open_time as $k => $v) {
                        $kp_time[$k] = strtotime($day . ' ' . $v['kp_time']);
                        $fp_time[$k] = strtotime($day . ' ' . $v['fp_time']);
                        $kj_time[$k] = strtotime($day . ' ' . $v['kj_time']);
                        $n_time      = time();
                        if ($n_time > $kp_time[$k] && $n_time < $kj_time[$k]) {
                            //  print_r($kp_time[$k]);exit;
                            $data['openTime']  = $kp_time[$k] . '000'; //开盘时间
                            $data['closeTime'] = $fp_time[$k] . '000'; //封盘时间
                            $data['drawTime']  = $kj_time[$k] . '000'; //开奖时间

                            $value = S('setting');
                            $n_day = strtotime(date('Ymd'));
                            $jiane = ($n_day - $value['twbg_day']) / (24 * 60 * 60);
                            if ($jiane == 1) {
                                $data['drawNumber'] = $value['twbg_period'] + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['twbg_period'] + $v['periods'] - 1; // 上期期号
                            } else {
                                $data['drawNumber'] = $value['twbg_period'] + ($jiane - 1) * 203 + $v['periods']; // 本期期期号
                                $data['pnumber']    = $value['twbg_period'] + ($jiane - 1) * 203 + $v['periods'] - 1; // 上期期号
                            }

                            if ($n_time > $kp_time[$k] && $n_time < $fp_time[$k]) {
                                $data['status'] = 1;
                            } else {
                                $data['status'] = 2;
                            }
                            $data['drawDate']    = strtotime($day) . '000'; // 开奖日期
                            $data['currentTime'] = time() . '000'; // 当前时间
                        }

                    }

                    // print_r($fp_time);exit;
                    if (!empty($data)) {
                        echo json_encode($data);exit(0);
                    } else {
                        echo json_encode('');exit(0);
                    }
                } else {
                    echo json_encode('');exit(0);
                }
                break;

            default:
                echo json_encode($data);exit(0);
                break;

        }

    }

}
